<script>
export default {
	onLaunch: function () {
		if (this.aiMenuList.length > 1) {
			// wx.setTabBarItem({
				// index: 0,
				// pagePath: "pages/index/index",
				// text: "AI助手",
				// iconPath: "/static/tabbar/home.png",
				// selectedIconPath: "/static/tabbar/home-active.png"
			// })
		}
	},
	computed: {
		aiMenuList() {
			return this.$store.state.workbench.aiMenuList
		}
	},
	onShow: function () {

		const updateManager = uni.getUpdateManager();
		// updateManager.onCheckForUpdate(function (res) {
		// 	// 获取当前页面在那个路径，如果是在特定的路径，那么就关闭页面
		// 	const pages = getCurrentPages();
		// 	if (pages.length > 0) {
		// 		let currentPage = pages[pages.length - 1];
		// 		let currentPath = `/${currentPage.route}` + '';
		// 		// if (currentPath === '/pages/WeChatMap/index') {
		// 		// 	wx.navigateBack({
		// 		// 		delta: 1
		// 		// 	});
		// 		// }
		// 	}
		// 	// 请求完新版本信息的回调
		// 	console.log('检测小程序版本---', res);
		// });
		updateManager.onUpdateReady(function (res) {
			uni.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启小程序？',
				success(res) {
					if (res.confirm) {
						// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						updateManager.applyUpdate();
					}
				}
			});
		});
		updateManager.onUpdateFailed(function (res) {
			// 新的版本下载失败
		});
		// #ifdef MP || MP-WEIXIN
		const this_ = this
		uni.getSystemInfo({
			success: (data) => {
				const systemInfo = uni.getSystemInfoSync();
				const screenWidth = systemInfo.screenWidth;
				let custom = uni.getMenuButtonBoundingClientRect();
				console.log('胶囊按钮位置', custom)
				let statusBarHeight = data.statusBarHeight;
				// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
				let navigationBarHeight = custom.height + (custom.top - statusBarHeight) * 2;
				// 总体高度 = 状态栏高度 + 导航栏高度
				let navHeight = navigationBarHeight + statusBarHeight;
				const capsuleWidth = custom.width;
				const capsuleLeft = custom.left;
				// 计算胶囊按钮距离右侧的距离
				const capsuleRightDistance = screenWidth - capsuleLeft - capsuleWidth;
				this_.$store.commit('setCommonHeight', { statusBarHeight, navigationBarHeight, navHeight, navWidth: custom.width, capsuleRightDistance });
			}
		})
		// #endif
		// #ifdef APP-PLUS
		
		// #endif
		this.setCommonHeight()

		// uni.getStorage({
		// 	key: 'accessToken',
		// 	success: function (res) {
		// 		let token = res.data
		// 		if (token) { // 如果已经是登录状态
		// 			this_.$Geting(this_.$api.autoApproval).then(response => {
		// 				if (response.code === '0') {
		// 					// this_.$store.dispatch('getUserApprovePro')
		// 					this_.$store.dispatch('getUserInfo')
		// 				}
		// 			})
		// 		}
		// 	}
		// })
	},
	onCreate: {

	},
	onHide: function () {
		console.log('App Hide')
		// 页面整个刷新触发
		// uni.setStorageSync('homeDataType', 1)
		// uni.setStorageSync('appAllList', [])
		// uni.setStorageSync('centerArrZJ', [])
		// uni.setStorageSync('homeData', [])
		// uni.setStorageSync('rentAppData', [])
		// uni.setStorageSync('rentHouseData', [])
		// uni.setStorageSync('rentBannerData', [])
	},
	methods: {
		setCommonHeight() {
			const this_ = this
			uni.getSystemInfo({
				success: (data) => {
					const systemInfo = uni.getWindowInfo();
					const screenWidth = systemInfo.screenWidth;
					let custom = {
						height: 0,
						top: 30,
						left: 0,
						width: 0
					}
					let statusBarHeight = data.statusBarHeight;
					// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
					let navigationBarHeight = 40 // custom.height + (custom.top - statusBarHeight) * 2 + 12;
					// 总体高度 = 状态栏高度 + 导航栏高度
					let navHeight = navigationBarHeight + statusBarHeight;
					const capsuleWidth = custom.width;
					const capsuleLeft = custom.left;
					// 计算胶囊按钮距离右侧的距离
					const capsuleRightDistance = 100 // screenWidth - capsuleLeft - capsuleWidth;
					console.log('statusBarHeight:', statusBarHeight, 'navigationBarHeight', navigationBarHeight, 'navHeight', navHeight, 'navWidth', custom.width, 'capsuleRightDistance', capsuleRightDistance, '------各种高度------');

					this_.$store.commit('setCommonHeight', { statusBarHeight, navigationBarHeight, navHeight, navWidth: custom.width, capsuleRightDistance });
				}
			})
		}
	}
}
</script>
<style >
@import '/wxcomponents/vant/common/index.wxss';
</style>
<style lang="scss">
/* #ifndef APP-NVUE */

@import "@/uni_modules/uview-ui/index.scss";
@import "@/styles/global.css";


// @import "@/wxcomponents/vant/common/index.wxss";


page {
	height: 100%;
	width: 100%;
	background-color: $uni-bg-color-grey;
	font-family: Source Han Sans CN-Regular, Source Han Sans CN;
}

.h100 {
	height: 100%;
}

.auth-txt {
	.h {
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(0, 0, 0, .2);
		z-index: 10;
	}

	.text {
		position: fixed;
		top: 40%;
		left: 50%;
		width: 60%;
		height: auto;
		transform: translate(-50%, 0);
		background: #fff;
		padding: 12px 24px;
		border-radius: 4px;
		font-size: 14px;
		z-index: 11;

		view {
			margin: 12px 0 0;
			padding-top: 10px;
			text-align: center;
			border-top: 1px solid #e5e5e5;
			color: #0095ff;
		}
	}
}

/* #endif */
</style>
